<?
if($_REQUEST["action"]=="data"){
	$itemID=substr($_REQUEST["id"],4);
	data($itemID);
}


if($_REQUEST["action"]=="attribuer"){
	$sql->query("update ".CFG_MYSQL_PREFIX."wishlist_item set eu=1, ts=".time()." where idItem=".$_REQUEST["id"]." and idPlayer=".$_REQUEST["idPlayer"]);

	data($_REQUEST["id"]);
}

if($_REQUEST["action"]=="enlever"){
	$sql->query("update ".CFG_MYSQL_PREFIX."wishlist_item set eu=0, ts=0 where idItem=".$_REQUEST["id"]." and idPlayer=".$_REQUEST["idPlayer"]);

	data($_REQUEST["id"]);
}


function data($itemID){
	global $sql;
	
	$liste=$sql->request("select * from ".CFG_MYSQL_PREFIX."wishlist_item where idItem=".$itemID." order by eu,ts");
	
	echo "<table style='width: 100%; border-top: 1px solid #000000;' cellpadding='2' cellspacing='0'>";

	foreach($liste as $wl){
		$player=getPlayerById($wl->idPlayer);
		echo "<tr class='ui-state-default cursor-default pointer' onmouseover='$(this).addClass(\"ui-state-hover\");' onmouseout='$(this).removeClass(\"ui-state-hover\");' ";
		if($wl->eu==1) echo "onclick='wishlist_enlever(".$itemID.",".$player->id.")' >";
		else echo "onclick='wishlist_attribuer(".$itemID.",".$player->id.")' >";
		echo "<td style=' width: 10px; border-bottom: 1px solid #000000;'><img src='images/classes/".$player->classe.".gif' alt='' /></td>";
		echo "<td style=' width: 10px; border-bottom: 1px solid #000000;'><img src='images/player/".$player->race."-".$player->sexe.".gif' alt='' /></td>";
		echo "<td style=' border-bottom: 1px solid #000000;'>".$player->nom."</td>";
		if($wl->eu==1) echo "<td style='text-align: right; border-bottom: 1px solid #000000;'>Recu le ".date("d/m/Y",$wl->ts)."</td>";
		else echo "<td style=' border-bottom: 1px solid #000000;'>&nbsp;</td>";
		echo "</tr>";
	}
	
	echo "</table>";
}

